package com.gxf.drugmg.service;

import com.gxf.drugmg.entity.Drug;
import com.gxf.drugmg.repository.DrugRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DrugService {
    
    @Autowired
    private DrugRepository drugRepository;
    
    public List<Drug> getAllDrugs() {
        return drugRepository.findAll();
    }
    
    public Drug getDrugById(Long id) {
        return drugRepository.findById(id).orElse(null);
    }
    
    public Drug saveDrug(Drug drug) {
        return drugRepository.save(drug);
    }
    
    public void deleteDrug(Long id) {
        drugRepository.deleteById(id);
    }
    
    public List<Drug> searchDrugsByName(String name) {
        return drugRepository.findByNameContainingIgnoreCase(name);
    }
    
    public List<Drug> getDrugsByManufacturer(String manufacturer) {
        return drugRepository.findByManufacturer(manufacturer);
    }
}